package Thread_;

public class Thread14 {
        //死锁场景2：
    public static void main(String[] args) {
        Object A=new Object();
        Object B=new Object();
        Thread t1=new Thread(()->{
            synchronized (A){
                try {
                    Thread.sleep(1000);//等待一下，让t2获取锁B
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized(B){
                    System.out.println("Thread run t1");
                }
            }
        });
        Thread t2=new Thread(()->{
            synchronized (B){
                try {
                    Thread.sleep(1000);//等待一下，让t2获取锁B
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized(A){
                    System.out.println("Thread run t2");
                }
            }
        });
        t1.start();
        t2.start();

    }
    public static void main1(String[] args) {
        //线程锁的“可重入”行
        Object locker=new Object();
        Thread t=new Thread(()->{
            synchronized(locker){
                synchronized(locker){
                    System.out.println("Thread run");
                }
            }
        });
        t.start();
    }
}
